// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const planRequest = {
  // dict请求的基本url
  BASE_URL: confing.CAL_URL + "/plan",

  // 根据分类查询计划
  selectByType(calendarType, callback) {
    let url = this.BASE_URL + "/selectByType?calendarType=" + calendarType;
    // 发送请求
    request.get(url,callback);
  },

  //删除计划
  deletes(planIds, callback) {
    // 拼接URL
    let url = this.BASE_URL + "/delete?t=1";
    if (planIds != undefined) {
      planIds.forEach(planId => {
        url += "&planIds=" + planId;
      });
      request.delete(url, callback);
    }
  },
  //修改计划
  update(calPlan, callback) {
    let url = this.BASE_URL + "/update";
    request.post(url, calPlan, callback);
  },
  //根据id查询排班计划详情
  selectByPlanId(planId, callback) {
    let url = this.BASE_URL + "/selectByPlanId?planId=" + planId;
    // 发送请求
    request.get(url, callback);
  },
  //添加计划数据
  save(calPlan, callback) {
    let url = this.BASE_URL + "/save";
    request.post(url, calPlan, callback);
  },
  // 分页查询
  list(page = 1, limit = 10, calPlan, callbcak) {
    // url
    let url = this.BASE_URL + "/list?page=" + page +
      "&limit=" + limit;
    if (calPlan) {
      if (calPlan.planCode) {
        url += "&planCode=" + calPlan.planCode;
      }
      if (calPlan.planName) {
        url += "&planName=" + calPlan.planName;
      }
      if (calPlan.startDate) {
        url += "&startDate=" + calPlan.startDate;
      }
      if (calPlan.endDate) {
        url += "&endDate=" + calPlan.endDate;
      }
      if (calPlan.calendarType) {
        url += "&calendarType=" + calPlan.calendarType;
      }
    }
    // 发送请求
    request.get(url, callbcak);
  }
}
// 将dictRequest暴漏出去
export default planRequest;